#include <stdio.h>
void main(){
    int m,n;
    scanf("%d %d",&m,&n);
    int a[m][n];
    for (int i=0; i<m; i++){
        for (int j=0; j<n;j++){scanf("%d",&a[i][j]);}
    }
    int row[m];
    for (int i=0; i<m; i++){
        row[i]=0;
        for (int j=0; j<n; j++){row[i]+=a[i][j];}
        printf("%d ",row[i]);
    }
    printf("\n");
    int column[n];
    for (int j=0;j<n; j++){
        column[j]=0;
        for (int i=0; i<m; i++){column[j]+=a[i][j];}
        printf("%d ",column[j]);
    }
    printf("\n");
}